﻿// Author - Owen Emlen (owene_1998@yahoo.com)
using System;
using System.Runtime.Serialization;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
#if USE_HYPER
using Hyper.ComponentModel;
#endif

namespace BrainTechLLC.ThreadSafeObjects
{
    /// <summary>
    /// Thread-safe lookup allows multiple threads to look up items by key, add items,
    /// and remove items in a thread-safe manner
    /// </summary>
#if NO_SILVERLIGHT
    [TypeDescriptionProvider(typeof(HyperTypeDescriptionProvider))]
#endif
    [Serializable]
    [DataContract]
    public class ThreadSafeLookupOnAutoKey<TIndex, TListType> : ThreadSafeLookup<TIndex, TListType>, IMultipleItems<TListType>,
        ISupportsCount, ISupportsAddRemoveClear<TIndex, TListType> where TListType : class, IKeyedOnProperty<TIndex>
    {
        public override string ToString()
        {
            return Count.ToString();
        }

        public bool Add(TListType item)
        {
            TIndex key = item.Key;
            return Add(key, item);
        }

        public void AddOrSet(TListType item)
        {
            TIndex key = item.Key;
            AddOrSet(key, item);
        }

        public bool Remove(TListType item)
        {
            TIndex key = item.Key;
            return Remove(item.Key);
        }
    }
}